package com.example.crm.dao;

import java.sql.SQLException;
import java.util.List;

import org.junit.Test;

import com.example.crm.pojo.Customer;
import com.example.crm.pojo.User;

import junit.framework.TestCase;

public class TestDemo {

	@Test
	public void test1() throws SQLException
	{
		UserDAO dao = new UserDAO();
		
		User u = new User();
		u.setUsername("zhangsa3");
		u.setPassword("123456");
		
		int result = dao.insert(u);
		
		// 断言
		TestCase.assertTrue(result==1);
	}
	
	@Test
	public void test2()throws SQLException
	{
		UserDAO dao = new UserDAO();
		
		User u = dao.findBy("zhangsan", "123456");
		
		// 断言
		TestCase.assertNotNull(u);
	}
	
	@Test
	public void test3() throws SQLException
	{
		CustomerDAO dao = new CustomerDAO();
		
		String name;
		int userId;
		int createId;
		
		String source;
		String industry;
		String level;
		
		String linkman;
		String phone;
		String mobile;
		Customer c = new Customer(-1,"刘备",1,1,"网络","机械","1级","曹操","110","123123123123");
		int result = dao.insert(c);
		
		TestCase.assertEquals(1, result);
		
	}
	
	@Test
	public void test4() throws SQLException
	{
		CustomerDAO dao = new CustomerDAO();
		List<Customer> list = dao.findAll();
		
		for(Customer c:list)
		{
			System.out.println(c);
		}
		TestCase.assertNotNull(list);
		TestCase.assertTrue(list.size()>0);
	}
	
	@Test
	public void test5() throws SQLException
	{
		CustomerDAO dao = new CustomerDAO();
		
		
		int result = dao.deleteById(2);
		
		TestCase.assertEquals(1, result);
		
	}
	
	@Test
	public void test6() throws SQLException
	{
		CustomerDAO dao = new CustomerDAO();
		Customer c = dao.findById(1);
		System.out.println(c);
		
		TestCase.assertNotNull(c);
	}
	
	@Test
	public void test7() throws SQLException
	{
		CustomerDAO dao = new CustomerDAO();
		

		Customer c = new Customer(1,"刘婵",1,1,"网络","机械","1级","曹操","110","123123123123");
		int result = dao.update(c);
		
		TestCase.assertEquals(1, result);
		
	}
	
}

//  java.sql.SQLException: Column count doesn't match value count at row 1
// 插入语句里面字段的数量和数据库里的字段不一致

